
//下面这几个包必须要导入才行 in_app_purchase
import 'package:base_pay/base_pay.dart';
import 'package:base_pay/manager/BasePayManager.dart';
import 'package:in_app_purchase/in_app_purchase.dart';
import 'package:in_app_purchase_storekit/in_app_purchase_storekit.dart';
import 'package:in_app_purchase_storekit/store_kit_wrappers.dart';

import 'IProductDetails.dart';

class IOSProductEntity implements IProductDetails {
  AppStoreProductDetails details;

  IOSProductEntity({
    required this.details,
  });

  @override
  String getCurrencySymbol() {
    return details.currencySymbol;
  }

  @override
  String getCurrentCode() {
    return details.currencyCode;
  }

  @override
  String getID() {
    return details.id;
  }

  @override
  String getPrice() {
    return details.price;
  }

  @override
  ProductDetails getProductDetails() {
    return details;
  }

  @override
  double getRawPrice() {
    return details.rawPrice;
  }

  @override
  bool? getFreeTry() {
    bool freetry = details.skProduct.introductoryPrice?.type == SKProductDiscountType.introductory;

    //必须要设置BasePayManager().setSubscribeGroupList()
    if (freetry) {
      List<SubscribeGroup> groupList = BasePayManager().getSubscribeGroupList();
      for (var group in groupList) {
        if (group.ids.contains(getID())) {
          if (group.didFreeTry != null) {
            return !(group.didFreeTry!);
          }
        }
      }
    }

    return freetry;
  }


}
